package sagroup.dracots.policy;


import java.util.logging.Logger;

import lime2.Location;
import sagroup.dracots.DracoReactionEvent;
import sagroup.dracots.DracoReactionListener;
import sagroup.dracots.PolicySwitcher;
import sagroup.dracots.TupleType;

public class PolicyReactionListener extends DracoReactionListener {

	private PolicySwitcher switcher;

	@SuppressWarnings("unused")
	private Logger LOG = Logger.getLogger(this.getClass().getName());

	public PolicyReactionListener(PolicySwitcher switcher) {
		this.switcher = switcher;
	}

	@Override
	public void reactsToWrite(DracoReactionEvent re) {
		RPTuple rpTuple = (RPTuple) re.getTuple();
		TupleType type = rpTuple.getTargetType();
		Location node = rpTuple.getTargetNode();
		ReplicationPolicy newPolicy = rpTuple.getPolicy();
		switcher.switchPolicy(type, node, newPolicy);
	}
}
